package app.beit.fintrack.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class DateFormatUtils {

	private static final String[] THAI_MONTHS = { "มกราคม", "กุมภาพันธ์",
			"มีนาคม", "เมษายน", "พฤษภาคม", "มิถุนายน", "กรกฎาคม", "สิงหาคม",
			"กันยายน", "ตุลาคม", "พฤศจิกายน", "ธันวาคม" };

	private static final SimpleDateFormat SF_DDMMYYYY_US = new SimpleDateFormat(
			"dd/MM/yyyy", Locale.US);

	public static Date strToDate(final String value) throws ParseException {
		return SF_DDMMYYYY_US.parse(value);
	}

	public static String dateToStr(final Date date) {
		return date == null ? "" : SF_DDMMYYYY_US.format(date);
	}

	public static String fullMonthThai(final Date date) {
		if (date == null) {
			return "";
		}
		final String afterDateFormat = dateToStr(date);
		final String[] tmps = afterDateFormat.split("/");
		return tmps[0] + " " + THAI_MONTHS[Integer.parseInt(tmps[1]) - 1] + " "
				+ (Integer.parseInt(tmps[2]) + 543);
	}

	public static String fullCurrentDate(final Date date) {
		if (date == null) {
			return "";
		}
		final String afterDateFormat = dateToStr(date);
		final String[] tmps = afterDateFormat.split("/");
		return tmps[0] + " " + THAI_MONTHS[Integer.parseInt(tmps[1]) - 1] + " "
				+ (Integer.parseInt(tmps[2]));
	}

	public static String convertDateToString(final Date date) {
		String strDate = "";
		if (date != null) {
			SimpleDateFormat formatDate = new SimpleDateFormat(
					"yyyy-MM-dd HH:mm", Locale.US);
			strDate = formatDate.format(date);
			String[] split = strDate.split("-");
			strDate = (Integer.parseInt(split[0]) + 543) +"-"+ split[1] +"-"+ split[2];
		}
		return strDate;
	}
	public static String DateThaiToDate(final Date date) {
		String Dateth ="";
		if(date!= null){
		SimpleDateFormat simple_date = new SimpleDateFormat("yyyyMMdd", new Locale("th", "th"));
		Dateth = simple_date.format(date);
		}
		return Dateth;
	}
	
	
}
